﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Abreu.Base.ViewModels.Interfaces;
//using Abreu.Base.Model.Interfaces;
using System.Collections.ObjectModel;
//using Abreu.Base.Model;
using System.Windows.Input;
using System.ComponentModel;
using CorpAbreu.Common.BaseClasses;
//using Abreu.Base.Commands;


namespace Abreu.Base.ViewModels
{
    public class MenuItensVM : IViewModel
    {


        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                if (propertyName.Equals("IsSelected", StringComparison.OrdinalIgnoreCase))
                {
                    if (this.IsSelected && this.ActionCommand != null && this.ActionCommand.CanExecute(null))
                    {
                        if (((DelegateCommand)this.ActionCommand).ObjectParameter != null)
                        {
                            this.ActionCommand.Execute(((DelegateCommand)this.ActionCommand).ObjectParameter);
                        }
                        else
                        {
                            this.ActionCommand.Execute(null);
                        }

                    }
                }
            }
        }

        void Teste()
        {
 
        }

        public MenuItensVM(string name)
        {
            this.Name = name;
            this.Children = new ObservableCollection<MenuItensVM>();
            this.ActionCommand = new DelegateCommand(Teste);
            this.Parent = null;
        }

        public MenuItensVM(string name, ICommand actionCommand)
        {
            this.Name = name;
            this.ActionCommand = actionCommand;
            this.Children = new ObservableCollection<MenuItensVM>();
            this.Parent = null;
        }

        public MenuItensVM(string name, MenuItensVM parent)
        {
            parent.Children.Add(this);
            this.Name = name;
            this.Children = new ObservableCollection<MenuItensVM>();
            this.Parent = parent;
        }

        public MenuItensVM(string name, MenuItensVM parent, ICommand actionCommand)
        {
            parent.Children.Add(this);
            this.Name = name;
            this.ActionCommand = actionCommand;
            this.Children = new ObservableCollection<MenuItensVM>();
            this.Parent = parent;
        }


        public MenuItensVM()
        {

        }

        
        public ObservableCollection<MenuItensVM> Children { get; set; }
        public bool IsExpanded
        {
            get
            {
                return _IsExpanded;
            }
            set
            {
                _IsExpanded = value;
                this.OnPropertyChanged("IsExpanded");
            }
        }
        private bool _IsExpanded;


        public bool IsSelected
        {
            get
            {
                return _IsSelected;
            }
            set
            {
                _IsSelected = value;
                OnPropertyChanged("IsSelected");
            }
        }
        private bool _IsSelected;

        public string Name { get; set; }

        private ICommand _ActionCommand;
        public ICommand ActionCommand
        {
            get { return _ActionCommand; }
            set
            {
                if (value != _ActionCommand)
                {
                    _ActionCommand = value;
                    OnPropertyChanged("ActionCommand");
                }
            }
        }


        public IViewModel Parent
        {
            get;
            set;
        }
    }
}
